package com.homestead.enums;

import lombok.Getter;
import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author HanBin_Yang
 * @since 2021/4/10 21:05
 */
public enum OrgTypeEnum {
    /**
     * 组织
     */
    PLATFORM(0, "平台", "PT"),
    GROUP(1, "集团", "ZB"),
    MERCHANT(2, "地区公司", "FGS"),
    STORE(3, "楼盘", "DP"),
    ;

    @Getter
    private final Integer orgLevel;
    @Getter
    private final String levelName;
    @Getter
    private final String orgLevelCode;

    OrgTypeEnum(Integer type, String name, String orgLevelCode) {
        this.orgLevel = type;
        this.levelName = name;
        this.orgLevelCode = orgLevelCode;
    }

    public static String getLevelNameByOrgLevel(Integer orgLevel) {
        Objects.requireNonNull(orgLevel);
        return Stream.of(values())
                .filter(bean -> bean.orgLevel.equals(orgLevel))
                .map(OrgTypeEnum::getLevelName)
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("orgLevel:" + orgLevel + " not exist!"));
    }

    public static OrgTypeEnum getEnumByOrgLevel(Integer orgLevel) {
        Objects.requireNonNull(orgLevel);
        return Stream.of(values())
                .filter(bean -> bean.orgLevel.equals(orgLevel))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("orgLevel:" + orgLevel + " not exist!"));
    }

    public static Integer getOrgLevelByOrgLevelCode(String orgLevelCode) {
        Objects.requireNonNull(orgLevelCode);
        return Stream.of(values())
                .filter(bean -> bean.orgLevelCode.equals(orgLevelCode))
                .map(OrgTypeEnum::getOrgLevel)
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("orgLevelCode:" + orgLevelCode + " not exist!"));
    }
}
